<%-- 
    Document   : RoleUpdate
    Created on : Nov 11, 2011, 10:24:46 PM
    Author     : Valentina
--%>

<%@page import="java.util.ResourceBundle"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>

<c:set var="language" value="${not empty param.language ? param.language : not empty language ? language : pageContext.request.locale}" scope="session" />
<fmt:setLocale value="${language}" />
<fmt:setBundle basename="Messages"/>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="default.css" rel="stylesheet" type="text/css" />
        <title><fmt:message key="page.text.roleupdate.title"/></title>
    </head>
    <body>

        <jsp:include page="/WEB-INF/frontend/commons/header.jspf"></jsp:include>

        <table width="740" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td><img src="images/spacer.gif" alt="" width="100" height="30" /></td>
                        </tr>
                        <tr>
                            <td class="title"><fmt:message key="page.text.roleupdate.title"/></td>
                        </tr>

                        <tr>
                            <td>
                                <ul class="error">
                                    <c:forEach var="error" items="${myErrors}" >
                                        <li>${error}</li>

                                    </c:forEach>
                                </ul>

                                <ul class="success">                                   
                                    <c:forEach var="success" items="${scflMessage}" >
                                        <li> ${success}</li>
                                    </c:forEach>
                                </ul>
                            </td>
                        </tr>
                        
                        <tr>
                            <td>
                                <c:choose>
                                    <c:when test="${role!=null}">
                                        <form action="RoleUpdateServlet?id=${role.id}" method="POST">
                                            <p>*<fmt:message key="page.text.name"/> <input type="text" name="name" value="${role.name}" size="20" /></p>
                                            <p>*<fmt:message key="page.text.description"/><input type="text" name="description" value="${role.description}" size="20" /></p>
                                            <p><fmt:message key="page.text.group"/>
                                                <c:forEach var="group" items="${groups}" varStatus="status">
                                                <tr>
                                                    <td>
                                                        <c:set var="val" value="0"/>
                                                        
                                                        <c:forEach var="rolegr" items="${role.groups}" varStatus="status">
                                                            <c:if test="${group.id == rolegr.id}">
                                                                 <c:set var="val" value="1"/>
                                                            </c:if>
                                                        </c:forEach> 
                                                        
                                                        <c:choose>
                                                            <c:when test="${val == 1}">
                                                                <input type="checkbox" name="idGroup" value="${group.id}" checked="true"/>${group.name}                                              
                                                            </c:when>
                                                            <c:otherwise>
                                                                <input type="checkbox" name="idGroup" value="${group.id}"/>${group.name}
                                                            </c:otherwise>
                                                        </c:choose>
                                                    </td>
                                                </tr>
                                            </c:forEach>
                                        
                                            <input type="submit" value="<fmt:message key="page.text.update"/>" /></p>
                                        </form> 
                                    </c:when>
                                    <c:otherwise>
                                        <form action="RoleUpdateServlet" method="POST">
                                            <p>*<fmt:message key="page.text.name"/> <input type="text" name="name" value="${name}" size="20" /></p>
                                            <p>*<fmt:message key="page.text.description"/><input type="text" name="description" value="${description}" size="20" /></p>
                                            <p><fmt:message key="page.text.group"/>
                                                
                                                <c:forEach var="group" items="${groups}" varStatus="status">
                                                <tr>
                                                    <td>
     
                                                      <input type="checkbox" name="idGroup" value="${group.id}"/>${group.name}
                                                        
                                                    </td>
                                                </tr>
                                            </c:forEach>
                                            </p>
                                            <p><input type="submit" value="<fmt:message key="page.text.update"/>" /></p
                                        </form>
                                    </c:otherwise>
                                </c:choose>

                                

                            </td>
                        </tr>   

                    </table>
                </td>
            </tr>
        </table>

        <jsp:include page="/WEB-INF/frontend/commons/footer.jspf"></jsp:include>

    </body>
</html>